﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;

namespace web.admin.scTask
{
    public partial class list : System.Web.UI.Page
    {
        ContestService contestService = new ContestService();
        CompetitionService competitionService = new CompetitionService();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater1.DataSource = contestService.getAllContests();
                Repeater1.DataBind();

                CompetitionsList.DataSource = competitionService.getAllCompetitions();
                CompetitionsList.DataTextField = "COM_NAME";
                CompetitionsList.DataValueField = "COM_ID";
                CompetitionsList.DataBind();
            }
        }
        protected void CompetitionList_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selCompetitionId = CompetitionsList.SelectedValue;
            IList<BoContests> contests = new List<BoContests>();
            if (selCompetitionId == "")
            {
                contests = contestService.getAllContests();
                    
            }
            else
            {
                contests = contestService.GetContestByCompetition(selCompetitionId); 
                
            }
            Repeater1.DataSource = contests;
            Repeater1.DataBind();
        }
        //批量删除
        protected void BatchDelete(object sender, EventArgs e)
        {
            int j = 0;
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {
                string id = ((HiddenField)Repeater1.Items[i].FindControl("Hf_id")).Value;
                CheckBox cb = (CheckBox)Repeater1.Items[i].FindControl("CbChoose");
                BoContests ccc = contestService.getContest(id);
                if (cb.Checked)
                {
                    contestService.DeleteContest(ccc);
                    j++;
                }
            }
            Response.Write("<script>alert('删除成功，共删除" + j + "条数据');window.location.href='InnerTask.aspx'; </script>");
            return;
        }
       
    }
}